home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gcctest / tests05.zoo / tsignl.c < prev    next >
C/C++ Source or Header  |  1992-03-28  |  928b  |  60 lines

  1. #include "ansidecl.h"
  2. #include <signal.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. #ifndef __USE_GNU
  8. #ifdef atarist
  9. #include <siglist.h>
  10. #define strsignal(s) signal_names[(s)]
  11. #else
  12. #define strsignal(s) ("signal FOO")
  13. #endif
  14. #endif
  15.  
  16. #ifndef __USE_GNU
  17. #ifdef sun
  18. #define raise(X) kill(getpid(), X)
  19. #endif
  20. #endif
  21.  
  22. int win = 0;
  23.  
  24. void
  25. DEFUN(handler, (sig), int sig)
  26. {
  27.   printf("Received signal %d (%s).\n", sig, strsignal(sig));
  28.   win = 1;
  29. }
  30.  
  31. int
  32. DEFUN_VOID(main)
  33. {
  34.   if (signal(SIGINT, handler) == SIG_ERR)
  35.     {
  36.       perror("signal: SIGINT");
  37.       return(EXIT_FAILURE);
  38.     }
  39.  
  40.   puts("Set handler.");
  41.  
  42.   printf("Sending myself signal %d.\n", SIGINT);
  43.   fflush(stdout);
  44.  
  45.   if (raise(SIGINT) < 0)
  46.     {
  47.       perror("raise: SIGINT");
  48.       return(EXIT_FAILURE);
  49.     }
  50.  
  51.   if (!win)
  52.     {
  53.       puts("Didn't get any signal.");
  54.       return(EXIT_FAILURE);
  55.     }
  56.  
  57.   puts("Got a signal.");
  58.   return(EXIT_SUCCESS);
  59. }
  60.